<?php

class bluejotConfiguration extends sfApplicationConfiguration
{
  public function configure()
  {
  	  //Register listeners
      $this->dispatcher->connect('applet.presave', array('AppletManager', 'preSave'));
      $this->dispatcher->connect('applet.postsave', array('AppletManager', 'postSave'));
      $this->dispatcher->connect('applet.preload', array('AppletManager', 'preLoad'));
      $this->dispatcher->connect('applet.postload', array('AppletManager', 'postLoad'));
 	  
      //set the theme directory
      sfConfig::set('bj_theme_name', 'white_album');
      sfConfig::set('bj_theme_dir', sfConfig::get('sf_web_dir').DIRECTORY_SEPARATOR.'themes'.DIRECTORY_SEPARATOR.sfConfig::get('bj_theme_name'));
  	  sfConfig::set('sf_app_module_dir', sfConfig::get('bj_theme_dir').DIRECTORY_SEPARATOR.'modules');
      sfConfig::set('sf_app_template_dir', sfConfig::get('bj_theme_dir').DIRECTORY_SEPARATOR.'templates');
  }

  public function getControllerDirs($moduleName)
  {
    $dirs = array();
    foreach (sfConfig::get('sf_module_dirs', array()) as $key => $value)
    {
      $dirs[$key.'/'.$moduleName.'/actions'] = $value;
    }

    $dirs[sfConfig::get('sf_app_dir').'/modules/'.$moduleName.'/actions'] = false;             // application

    foreach ($this->getPluginPaths() as $path)
    {
      if (is_dir($dir = $path.'/modules/'.$moduleName.'/actions'))
      {
        $dirs[$dir] = true;                                                                   // plugins
      }
    }

    $dirs[sfConfig::get('sf_symfony_lib_dir').'/controller/'.$moduleName.'/actions'] = true;  // core modules

    return $dirs;
  }

  public function getTemplateDirs($moduleName)
  {
    $dirs = array();
    foreach (sfConfig::get('sf_module_dirs', array()) as $key => $value)
    {
      $dirs[] = $key.'/'.$moduleName.'/templates';
    }

    $dirs[] = sfConfig::get('sf_app_module_dir').'/'.$moduleName;                  // application
    $dirs = array_merge($dirs, $this->getPluginSubPaths('/modules/'.$moduleName.'/templates')); // plugins
    $dirs[] = sfConfig::get('sf_symfony_lib_dir').'/controller/'.$moduleName.'/templates';      // core modules
    $dirs[] = sfConfig::get('sf_module_cache_dir').'/auto'.ucfirst($moduleName.'/templates');   // generated templates in cache

    return $dirs;
  }
  
}
